from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `chat_exclusive_key` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `exclusive_key` LONGTEXT NOT NULL  COMMENT '密钥',
    `count` INT NOT NULL  COMMENT '次数',
    `expiration_time` DATETIME(6) NOT NULL  COMMENT '过期时间',
    `order_id` INT   COMMENT '订单ID'
) CHARACTER SET utf8mb4;;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP TABLE IF EXISTS `chat_exclusive_key`;"""
